package com.chixing.controller;

import com.chixing.entity.Myorder;
import com.chixing.service.IMyorderService;
import com.chixing.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author smith
 * @since 2025-05-21
 */
@RestController
@RequestMapping("/myorder")
public class MyorderController {

    @Autowired
    private IMyorderService myorderService;

    @GetMapping("/{myorderId}")
    public Result getById(@PathVariable("myorderId") Integer myorderId) {
        return myorderService.getById(myorderId);
    }

    @PostMapping
    public Result save(@RequestBody Myorder order){
        order.setOrderCreateTime(LocalDateTime.now());
        order.setOrderNumber(UUID.randomUUID().toString().replace("-",""));
        return myorderService.saveorder(order);
    }

    @GetMapping("/user/{custId}")
    public Result getOrdersByUser(@PathVariable Integer custId) {
        return myorderService.getOrdersByUserId(custId);
    }
}
